package cn.ybk.system.controller;


import cn.ybk.basic.util.AjaxResult;
import cn.ybk.basic.util.PageList;
import cn.ybk.system.domain.SystemType;
import cn.ybk.system.query.SystemTypeQuery;
import cn.ybk.system.service.SystemTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/type")
public class SystemTypeController {

    @Autowired
    private SystemTypeService systemTypeService;

    @GetMapping
    public List<SystemType> findAll() {
        return systemTypeService.findAll();
    }

    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody SystemType systemType) {
        Long id = systemType.getId();
        if (id == null) {
            systemTypeService.add(systemType);
        } else {
            systemTypeService.update(systemType);
        }
        return new AjaxResult().me().success();
    }

    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        systemTypeService.delete(id);
        return new AjaxResult().me().success();
    }

    // 分页 + 查询
    @PostMapping
    public PageList<SystemType> queryByPage(@RequestBody SystemTypeQuery query) {
        return systemTypeService.queryByPage(query);
    }

    @PatchMapping
    public AjaxResult batch(@RequestBody List<Long> ids) {
        systemTypeService.batch(ids);
        return AjaxResult.me().success();
    }




}
